package com.yitiao.data_algorithms.leetcode.editor.cn;

class B1IidL {
    // 2023-02-22 16:02:02
    public static void main(String[] args) {
        Solution solution = new B1IidL().new Solution();
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public int peakIndexInMountainArray(int[] arr) {
            if (arr.length == 3) return arr[1];
            int l = 1;
            int r = arr.length - 2;
            while (l <= r) {
                int mid = l + (r - l) / 2;
                if (arr[mid] > arr[mid + 1] && arr[mid] > arr[mid - 1]) {
                    return mid;
                } else if (arr[mid] < arr[mid + 1] && arr[mid] > arr[mid - 1]) {
                    l = mid + 1;
                } else {
                    r = mid - 1;
                }
            }
            return 0;
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}